//
//  HWPromoteProtocol.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/1/27.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit

class HWPromoteProtocol: NSObject {
    var scrollDidScroll:((_:UIScrollView)->())?
    var models:[HWPromoteGameModel]?
    var hideNav = true
    var didClickGame:((_ model:HWPromoteGameModel)->())?
}

extension HWPromoteProtocol:UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        didClickGame?(models?[indexPath.row] ?? HWPromoteGameModel())
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let header = UIView()
        header.frame = CGRect(x: 0, y: 0, width: screenWidth, height: 0)
        header.backgroundColor = .colorWithHexString(hexString: "#F5F5F5")
        return header
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if hideNav == true {
            return 0
        }
        return 10*widthScale
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return models?.count ?? 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let promoteCell = HWPromoteCell.cellWithTableView(tableView: tableView)
        promoteCell.model = models?[indexPath.row]
        promoteCell.indexPath = indexPath
        return promoteCell
    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        self.scrollDidScroll?(scrollView)
    }
}
